/* Authors CLR & DSL */

import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.IOException;
import javax.swing.JLabel;
import javax.swing.table.TableModel;
import javax.swing.JTable;
import java.util.ArrayList;

public class EventHandler {

	//CREATE_MEMBER
	public static void createMember(String fullName, String dateOfBirth, String memberType,
                                        String gender, boolean paid, String address, String phoneNumber, JLabel jStatus)
									 throws FileNotFoundException{
	
		MemberList memberList = new MemberList();
		Member newMember = new Member(fullName, dateOfBirth, memberType, gender, paid, address, phoneNumber);
		memberList.saveObject("members.xml", newMember);
                jStatus.setForeground(Color.GREEN);
                jStatus.setText("Member Created!");
	
	}

	//CREATE_COACH
	public static void createCoach(String fullName, String address, String phoneNumber) throws FileNotFoundException{
	CoachList coachList = new CoachList();
	Coach newCoach = new Coach(fullName, address, phoneNumber);
	coachList.saveObject("coaches.xml", newCoach);
	
	}

        
        public static void viewMembers(JTable jMemberTable) throws FileNotFoundException{
        
        
        MemberList memberList = new MemberList();
        ArrayList<DataObject> allMembers = new ArrayList<DataObject>();

        allMembers = memberList.loadAllObjectsFromFile("members.xml");

        for(int i=0; i<allMembers.size(); i++) {
            System.out.println("Member = "+allMembers.get(i));
            System.out.println("Name = "+allMembers.get(i).getFullName());
 


        
        
        TableModel members = jMemberTable.getModel();

        members.setValueAt(allMembers.get(i).getFullName(), i, i);
        members.setValueAt(allMembers.get(i).getFullName(), i, i);
        members.setValueAt(allMembers.get(i).getFullName(), i, i);
        members.setValueAt(allMembers.get(i).getFullName(), i, i);
        members.setValueAt(allMembers.get(i).getFullName(), i, i);
        members.setValueAt(allMembers.get(i).getFullName(), i, i);
        members.setValueAt(allMembers.get(i).getFullName(), i, i);
        } // end for.
        
        
        } // end viewMembers.
} // end class.